#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
增加初始化DB的示例，详细资料参考：
http://www.pythondoc.com/flask-sqlalchemy/contexts.html
"""
import random
import time

from faker import Faker

from application.models import db, User
from manage import app

fake = Faker('zh_CN')
fake_en = Faker()


def init_db():
    u = User()
    u.id = int(time.time() * 100000000)
    u.name = fake.word()
    u.email = fake_en.email()
    u.phone = random.randint(13900000000, 13999999999)
    u.password = '123456'
    db.session.add(u)
    db.session.commit()


if __name__ == '__main__':
    app.app_context().push()
    init_db()
